class CreateWebUsers < ActiveRecord::Migration
  def self.up
    create_table :web_users do |t|
      t.string :user_name           ,:limit => 20
      t.string :phone               ,:limit => 26 #个人电话.
      t.string :email               ,:limit => 30
      t.string :company_name        ,:limit => 50
      t.string :company_phone       ,:limit => 26
      t.string :company_fax         ,:limit => 26
      t.string :post_code           ,:limit => 10
      t.string :sex                 ,:limit => 6
      t.string :login_id            ,:limit => 15
      t.string :password            ,:limit => 16
      t.string :card_type_id        ,:limit => 10  #证件类型，l暂时不用，直接用card当身份证
      t.string :card                ,:limit => 30  #证件号
      t.string :address             ,:limit => 50
      t.string :login_ip            ,:limit => 30
      t.string :limited_ip          ,:limit => 60
      t.string :user_type           ,:limit => 16 #供应商或代理人 offer 或agent 或 all 即是代理也是供应,admin即为管理员
      t.integer :is_online          ,:limit => 1  ,:default => 0
      t.string :remark
      t.integer :order_amount       ,:limit => 3  ,:default => 0#用来记录当天此用户一共收到了多少定单。每天某时清零。
      t.integer :is_locked          ,:limit => 1  ,:default => 0 #是否管理会要锁定 1为True 0为False,如果用户已经锁定了，此用户不可登录。
      t.integer :lock_version    , :default => 0 #乐观锁
      t.timestamps
    end
    
    add_index :web_users, :user_name ,:unique=>true
    WebUser.create(:user_name => '未指定人员',:login_id =>'',:password =>'666',:sex=>'男',:phone=>'1370000001',:email=>'MikeMama@hotmail.com',:address=>'山东青岛',:card=>'3702060000000',:company_name =>'爱可',:company_phone=>'13700000000',:company_fax=>'88888888',:post_code=>'266000',:user_type=>'OFFER',:order_amount=>'1')
    WebUser.create(:user_name => 'Mike',:login_id =>'Mike',:password =>'666',:sex=>'男',:phone=>'1370000001',:email=>'MikeMama@hotmail.com',:address=>'山东青岛',:card=>'3702060000000',:company_name =>'爱可',:company_phone=>'13700000000',:company_fax=>'88888888',:post_code=>'266000',:user_type=>'OFFER',:order_amount=>'1')
    WebUser.create(:user_name => 'Jerry',:login_id =>'Jerry',:password =>'666',:sex=>'男',:phone=>'1370000002',:email=>'Jerry@hotmail.com',:address=>'山东青岛',:card=>'3702060000001',:company_name =>'爱可',:company_phone=>'13700000002',:company_fax=>'88888888',:post_code=>'266000',:user_type=>'OFFER',:order_amount=>'2')
    WebUser.create(:user_name => 'Peter',:login_id =>'Peter',:password =>'666',:sex=>'男',:phone=>'1370000003',:email=>'Peter@hotmail.com',:address=>'山东青岛',:card=>'3702060000002',:company_name =>'爱可',:company_phone=>'13700000003',:company_fax=>'88888888',:post_code=>'266000',:user_type=>'OFFER',:order_amount=>'3')
    WebUser.create(:user_name => 'Admin',:login_id =>'Admin',:password =>'666',:sex=>'男',:phone=>'1370000003',:email=>'Peter@hotmail.com',:address=>'山东青岛',:card=>'3702060000002',:company_name =>'爱可',:company_phone=>'13700000003',:company_fax=>'88888888',:post_code=>'266000',:user_type=>'ADMIN',:order_amount=>'3')
  end
  
  def self.down
    drop_table :web_users
  end
end
